package com.liuzw.order.controllers;
import com.liuzw.order.Order;
import com.liuzw.order.annotation.Log;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author 刘志伟
 * @create 2023/2/8 9:43
 */
@RestController
@RequestMapping("orders")
public class OrderController {

    /**
     * 获取订单列表
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    public List<Order> getList(){
        List<Order> orders = new ArrayList<Order>();

        Order item = Order.builder()
                .orderName ("采购订单")
                .amount(new BigDecimal(100))
                .cargoType(100)
                .id("0001")
                .build();

        orders.add(item);
        return orders;
    }

    /**
     * 根据id获取订单明细
     * @param id
     * @return
     */
    @Log(value = "注解式耗时统计")
    @GetMapping("/{id}")
    @ResponseBody
    public Order getOrderItem(@PathVariable(value = "id") String id){

        Order item = Order.builder()
                .orderName ("采购订单")
                .amount(new BigDecimal(100))
                .cargoType(100)
                .id(id)
                .build();
        return item;
    }
}
